package com.SmartCare.common;

import com.SmartCare.common.enums.Constants;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

//统一响应结果包装类
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result implements Serializable {
    //响应码，请求结果
    private String code;
    //请求失败，失败信息
    private String msg;
    //成功，返回数据
    private Object data;

    //成功时返回方法
    public static Result success(){
        return new Result(Constants.CODE_200,"",null);
    }
    public static Result success(Object data){
        return new Result(Constants.CODE_200,"",data);
    }
    public static Result success(String msg){
        return new Result(Constants.CODE_200,msg,null);
    }
    public static Result success(String msg,Object data){
        return new Result(Constants.CODE_200,msg,data);
    }
    //默认错误方法
    public static Result error(String code,String msg){
        return new Result(code,msg,null);
    }

    public static Result error() {
        return new Result(Constants.CODE_500, "系统错误", null);
    }
    public static Result error(String msg){
        return new Result(Constants.CODE_400,msg,null);
    }
    public static Result error(String msg,Object data){
        return new Result(Constants.CODE_400,msg,data);
    }
}
